/*
 * Project Name spring-boot-tools
 * File Name CodecFactory
 * Package Name com.huxiaosu.tools.cmpp.codec
 * Create Time 2024/4/18
 * Create by name：liujie
 */
package com.huxiaosu.tools.cmpp.codec;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

/**
 * Description
 *
 * @author liujie
 * @date 2024/4/18 23:35
 */
public class CodecFactory implements ProtocolCodecFactory {

    /**
     * 编码器
     */
    private final MPMessageEncoder encoder;

    /**
     * 解码器
     */
    private final MPMessageDecoder decoder;

    public CodecFactory(String charset) {
        encoder = new MPMessageEncoder(charset);
        decoder = new MPMessageDecoder(charset);
    }

    @Override
    public ProtocolEncoder getEncoder(IoSession session) throws Exception {
        return encoder;
    }

    @Override
    public ProtocolDecoder getDecoder(IoSession session) throws Exception {
        return decoder;
    }

}
